import { VuexModule, Module, Mutation, Action, getModule } from 'vuex-module-decorators'
import store from '@/store'
import request from '@/utils/request'
import { resolve } from 'path';
@Module({ dynamic: true, store, name: 'conf' })
export class ConfRepo extends VuexModule{

    
    // private  CacheObj:any=null;

    private globalCache:any;
    @Action
    public fieldInfo(name:string=''):Promise<any>{

        return new Promise((resolve,reject)=>{
            if(!this.globalCache){
                request({
                    url:'/conf/field-info',
                    method:'get',
                    params:{entity:name}
                }).then(data=>{
                    this.globalCache=data.data;
                    resolve(this.globalCache);
                })
            }else{
                resolve(this.globalCache);
            }
           
        });
       
    }
    /**
     * 
        获取数据字典列表
     * @GetMapping("dic-ls")
    public RpnMsg<Page<PerfmDic>> findDic(
            @RequestParam(defaultValue = "") String docType,
            @RequestParam(defaultValue = "") String id,
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String s
     */
    @Action
    public dicls(
        query:{docType:string,id:String,pageIndex:Number,pageSize:number,s:String}={
        s: '', pageIndex: 1, pageSize: 20, docType: '',
        id: ''
    }){
        return request({
            url:'/conf/dic-ls',
            method:'get',
            params:query
        })
    }

    /**
     * 一次添加或修改添加或修改字典
     * @param m {
                "code": "string",
                "enable": true,
                "id": "string",
                "join": {
                    "name": "string",
                    "parent": "string"
                },
                "mark": "string",
                "name": "string",
                "val": "string"
                }
     * @returns 
     */
    @Action
    public dicSave(m:any){
       return request.post('/conf/dic-save',m);
        // return request({
        //     url:'/conf/dic-save',
        //     method:'post',
        
        // })
    }


    @Action
    public dicChildByCode(m:any){
       return request({
           url:'/conf/dic-child-bycode',
           method:'get',
           params:m
       })
    
    }

    /**
     * 删除字典配置
     * @param ids 要删除的IDS
     * @returns 
     */
    @Action
    public dicDestorybyids(ids:Array<any>){
        return request.post('/conf/dic-destory-byids',ids);
    }
}
export const ConfModule = getModule(ConfRepo)